package io.renren.htby.utils;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class IOTSUtils {
	
	/** 当前系统id */
	public static Integer THIS_SYSTEM_ID = 7;
	
	/** Timer延迟时间 delay:延迟 */
	public static int MONITOR_TIMER_DELAY_TIME;

	/** Timer间隔时间 interval间隔 */
	public static int MONITOR_TIMER_INTERVAL_TIME;
	
	@Value("${sysconfig.monitorTimer.delayTime}")
	public void setMONITOR_TIMER_DELAY_TIME_STR(String delayTime) {
		IOTSUtils.MONITOR_TIMER_DELAY_TIME = Integer.parseInt(delayTime);
	}

	@Value("${sysconfig.monitorTimer.intervalTime}")
	public void setMONITOR_TIMER_INTERVAL_TIME_STR(String intervalTime) {
		IOTSUtils.MONITOR_TIMER_INTERVAL_TIME = Integer.parseInt(intervalTime);
	}
	
	@Value("${server.thisServerId}")
	public void setTHIS_SYSTEM_ID(String THIS_SYSTEM_ID) {
		IOTSUtils.THIS_SYSTEM_ID = Integer.parseInt(THIS_SYSTEM_ID);
	}
	
	 /**
     * 得到随机的22位UUID
     * @return 22位UUID
     */
    public static String getUUID() {
        StringBuilder sb = new StringBuilder("0");
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replaceAll("-", "");
        sb.append(uuid);
        uuid = NewLang.hexTo64(sb.toString());
     
        //System.out.println("uuid:"+uuid);
        return uuid;
    }
	
}
